import Vue from 'vue'
import VueRouter from 'vue-router'

// 1.导入 注册, 登录组件
import Reg from '@/views/Reg/Reg.vue'
import Login from '@/views/Login/Login.vue'
import Main from '@/views/Main/Main.vue'

import Home from '@/views/Menus/Home/Home.vue'
import UserInfo from '@/views/Menus/User/Userinfo.vue'
import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
import UserPwd from '@/views/Menus/User/UserPwd.vue'
import ArtCate from '@/views/Menus/Article/ArtCate.vue'
// 导入路由组件
import ArtList from '@/views/Menus/Article/ArtList.vue'

Vue.use(VueRouter)

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 2.在数组中声明路由规则
const routes = [
  { path: '/reg', component: Reg },
  { path: '/login', component: Login },
  {
    path: '/',
    component: Main,
    // 3. 开启路由重定向
    redirect: '/home',
    children: [
      // 2. home 作为 子路由规则
      { path: 'home', component: Home },
      { path: 'user-info', component: UserInfo },
      // UserAvatar 是子路由所以写在 children 里面, path 看网页跳转的地址, 上面引入UserAvatar
      { path: 'user-avatar', component: UserAvatar },
      // 重置密码的子路由规则
      { path: 'user-pwd', component: UserPwd },
      { path: 'art-cate', component: ArtCate },
      { path: 'art-list', component: ArtList }

    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
